package com.zatech.cgnci.project.controller;


import com.zatech.cgnci.project.service.CgnciReinsuranceRiskLayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 分入分出层表 前端控制器
 * </p>
 *
 * @author Generator
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/api/reinsurance-risk-layer")
@Api(produces = "application/json", tags = "分入分出险种层api接口文档")
@RequiredArgsConstructor
public class CgnciReinsuranceRiskLayerController {

    private final CgnciReinsuranceRiskLayerService cgnciReinsuranceRiskLayerService;

    @GetMapping("/deleteById")
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation(value = "删除")
    public void deleteById(@RequestParam(value = "layerId") Long layerId,
                           @RequestParam(value = "type") @ApiParam(value = "删除模块(1-分入险种层,2-分出险种层,3-分入方案/再保人险种层)") String type) {
        cgnciReinsuranceRiskLayerService.deleteLayer(layerId, type);

    }

    @GetMapping("/deleteByIds")
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation(value = "批量删除")
    public void deleteByIds(@RequestParam(value = "layerIds") String layerIds,
                            @RequestParam(value = "type") @ApiParam(value = "删除模块(1-分入险种层,2-分出险种层,3-分入方案/再保人险种层)") String type) {
        List<Long> idList = Arrays.stream(layerIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
        idList.forEach(id -> cgnciReinsuranceRiskLayerService.deleteLayer(id, type));
    }

}

